package org.tp8.ektelesis.swing;

import java.util.LinkedList;
import java.util.List;

import javax.swing.ListModel;
import javax.swing.event.ListDataListener;

import org.tp8.ektelesis.model.SearchResult;

public class SearchResultListModel implements ListModel<String> {

	private List<SearchResult> list = new LinkedList<SearchResult>();

	public SearchResultListModel(List<SearchResult> list) {
		this.list = list;
	}

	@Override
	public int getSize() {
		return list.size();
	}

	@Override
	public String getElementAt(int index) {
		String display = list.get(index).getPath();

		if (display.length() > 80) {
			int beginIndex = display.length() - 30;
			display = "..." + display.substring(beginIndex);
		}

		return display;
	}

	@Override
	public void addListDataListener(ListDataListener l) {

	}

	@Override
	public void removeListDataListener(ListDataListener l) {

	}
	
	public SearchResult get(int index) {
		return list.get(index);
	}
}
